package controllers.manager;

import java.io.File;
import java.io.IOException;

import play.Play;
import play.mvc.Controller;
import play.mvc.With;

@With(UserLoginFilter.class)
public class Manager extends Controller
{
    public static void index()
    {
        render("/manager/manager.html");
    }

    /**
     * 用户登录
     */
    public static void userLogin()
    {
        render("/manager/Manager/userLogin.html");
    }

    public static void login(String uname, String pwd)
    {
        if (uname == null || uname.length() == 0)
        {
            renderArgs.put("error_msg", "用户名长度不足");
            render("/manager/Manager/userLogin.html");
            return;
        }
        if (pwd == null || pwd.length() == 0)
        {
            renderArgs.put("error_msg", "密码不能为空");
            render("/manager/Manager/userLogin.html");
            return;
        }
        if (uname.equals(Play.configuration.get("user"))
                && pwd.equals(Play.configuration.get("pwd")))
        {
            session.put("user", uname);
            index();
        }
        else
        {
            renderArgs.put("error_msg", "用户名或密码错误");
            render("/manager/Manager/userLogin.html");
        }
    }

    public static void exit()
    {
        session.remove("user");
        userLogin();
    }

    public static void addShopItem()
    {
        render("/manager/Manager/addShopItem.html");
    }

    public static void getShopItemList()
    {
        render("/manager/Manager/getShopItemList.html");
    }
}
